#ifndef CPP_PROGRESSBAR_H
#define CPP_PROGRESSBAR_H

#include <widget/View.h>

class TextView;
class Point;

//@brief 进度条
//@author cvte
//@description 进度条控件
class ProgressBar : public View {
   public:
    class OnProgressBarChangeListener {
       public:
        virtual void onProgressBarProgressChanged(ProgressBar& progressBar, int progress);
        virtual void onProgressBarFocusChanged(ProgressBar& progressBar, bool getFocus); //焦点改变时的通知
    };

    ProgressBar();
    ~ProgressBar();

    void setMin(int min);
    void setMax(int max);
    //@method 设置进度，并触发回调
    void setProgress(int progress);
    //@method 设置进度，shouldTriggerCallback为true就触发回调，否则不触发回调
    void setProgress(int progress, bool shouldTriggerCallback);
    void incrementProgressBy(int diff);
    int getMin();
    int getMax();
    int getProgress();

    void setProgressBitmapEmpty(Bitmap& bitmap);
    void setProgressBitmapFull(Bitmap& bitmap);
    void setProgressBitmapShow(Bitmap& bitmap); //已不强制要求设置，控件内部会自动创建和释放该图像资源（这里指定进度条的实际显示数据资源（会被修改），对应的资源路径复用empty或full的即可）
    //@method 设置滑块图片
    void setProgressBitmapPointer(Bitmap& bitmap);
    //@method emptyPos是进度为0时，滑块指针中心位置坐标，fullPos是进度为100时，滑块指针中心位置坐标
    void setPointerPos(Point emptyPos, Point fullPos);
    //@method 设置滑块指针是否可见
    void setPointerVisible(bool isVisible);

    void setTextView(TextView& textView);
    TextView* getTextView();
    void setOnProgressBarChangeListener(OnProgressBarChangeListener& listener);

   protected:
    int mProgress = 0;
    int mMin = 0;
    int mMax = 100;
    Bitmap* mProgressBitmapEmpty = nullptr;
    Bitmap* mProgressBitmapFull = nullptr;
    Bitmap* mProgressBitmapShow = nullptr;
    Bitmap* mProgressBitmapPointer = nullptr;
    Point mEmptyPointerPos; //进度为0时，滑块指针中心位置坐标
    Point mFullPointerPos; //进度为100时，滑块指针中心位置坐标
    bool mPointerIsVisible = false;
    bool mIsAutoCreateProgressBitmapShow = false; //是否自动创建的show图像

    TextView* mTextView = nullptr;
    OnProgressBarChangeListener* mListener = nullptr;

    void onAttachedToWindow();
    void onDetachedFromWindow();
    void onDraw(Canvas& canvas);
    void onTouched(MotionEvent& event);
    void onScrolled(MotionEvent& event);

    virtual int pointToProgress(int x, int y);
};

#endif /* CPP_PROGRESSBAR_H */